package ita.class1.group2.supermarket.customer.handler;

import ita.class1.group2.supermarket.customer.dto.StoreDetailInfomation;
import ita.class1.group2.supermarket.customer.pojo.Store;
import ita.class1.group2.supermarket.customer.pojo.StoreInformation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DataHandler {

    public static List<StoreDetailInfomation> packingData(List<Store> stores, List<StoreInformation> storeInformations) {
        List<StoreDetailInfomation> storeDetailInfomations = new ArrayList<>();
        Map<String, StoreDetailInfomation> storeDetailInfomationMap = new HashMap<>();
        for (StoreInformation storeInformation : storeInformations) {
            StoreDetailInfomation storeDetailInfomation = new StoreDetailInfomation();
            storeDetailInfomation.setOpen(storeInformation.getOpen());
            storeDetailInfomation.setClose(storeInformation.getClose());
            storeDetailInfomation.setDeliveryArea(storeInformation.getDeliveryArea());
            storeDetailInfomation.setDescription(storeInformation.getDescription());
            storeDetailInfomation.setImages(storeInformation.getImages());
            storeDetailInfomation.setsId(storeInformation.getsId());
            storeDetailInfomationMap.put(storeInformation.getsId(),storeDetailInfomation);
           
        }
        System.out.println("Hnndler pre size:"+storeDetailInfomationMap.size());
        for (Store store : stores) {
            StoreDetailInfomation detailInfomation = storeDetailInfomationMap.get(store.getId());
            if(detailInfomation!=null){
                detailInfomation.setName(store.getName());
                detailInfomation.setAddress(store.getAddress());
                detailInfomation.setLicense(store.getLicense());
                storeDetailInfomations.add(detailInfomation);
            }
        }
        System.out.println("Hnndler after size:"+storeDetailInfomationMap.size());
        return storeDetailInfomations;
    }

    public static  StoreDetailInfomation packIntoDetailInfomation(Store store, StoreInformation storeInformation){
        StoreDetailInfomation storeDetailInfomation = new StoreDetailInfomation();
        storeDetailInfomation.setsId(store.getId());
        storeDetailInfomation.setName(store.getName());
        storeDetailInfomation.setAddress(store.getAddress());
        storeDetailInfomation.setLicense(store.getLicense());
        storeDetailInfomation.setDescription(storeInformation.getDescription());
        storeDetailInfomation.setDeliveryArea(storeInformation.getDeliveryArea());
        storeDetailInfomation.setClose(storeInformation.getClose());
        storeDetailInfomation.setOpen(storeInformation.getOpen());
        storeDetailInfomation.setImages(storeDetailInfomation.getImages());
        return storeDetailInfomation;
    }
}
